package org.springbus.ff.node;

import org.springbus.ff.conf.FFBaseConf;
import org.springbus.ff.core.FFCommand;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.Buffer;
import java.util.List;

public class FFImage  extends FFNode {
    public  FFImage(FFBaseConf conf){
        super(conf,"image");
        this.hasInput = true;
    }
    public  FFImage(FFBaseConf conf,String type){
        super(conf,type);
    }

    /**
     * Add ffmpeg input
     * ex: loop 1 -t 20  -i imgs/logo.png
     *
     * @private
     */
    public void addInput(FFCommand command) {
        command.addInput(this.getPath());
    }

    /**
     * Get image path
     *
     * @public
     */
    public String getPath() {
        if (conf.getPath() != null) {
            return this.conf.getPath();
        }
        if (this.conf.getImage() != null) {
            return this.conf.getImage();
        } else {
            return this.conf.getUrl();
        }
    }
   public void  setImageSize()  {
       if (this.w > 0) return;

       String path = this.getPath();
       try {
           BufferedImage image = ImageIO.read(new File(path));
           this.w=image.getWidth();
           this.h=image.getHeight();
       }catch (Exception ex){

       }
   }
   public boolean isReady() {
        setImageSize();
        return true;
    }

}
